from .celery import app
from libs.send_tx_sms import send_sms_by_mobile
import time, random


@app.task
def send_sms(mobile, code):
    res = send_sms_by_mobile(mobile, code)
    if res:
        return '%s的短信发送成功，验证码是%s,1314' % (mobile, code)
    else:
        return '%s的短信发送失败' % mobile


@app.task
def sckill_goods(name):
    # 逻辑是：开启事务---》扣减库存---》生成订单
    import time
    time.sleep(1)
    res = random.choice([100, 101])
    print(res)
    print(1111)
    if res == 100:
        print('%s被秒杀成功了' % name)
        return True
    else:
        print('%s被秒杀失败了' % name)
        return False
